package com.example.dllo.baidumusic.main;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import com.example.dllo.baidumusic.bean.MusicBean;
import com.example.dllo.baidumusic.events.MusicListEvent;
import com.example.dllo.baidumusic.nettool.FormatCodeUtil;
import com.example.dllo.baidumusic.R;
import com.example.dllo.baidumusic.bean.SearchBean;
import com.example.dllo.baidumusic.nettool.BaseActivity;
import com.example.dllo.baidumusic.nettool.NetTool;
import com.example.dllo.baidumusic.nettool.URLValuas;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by dllo on 16/9/5.
 */
public class SearchActivity extends BaseActivity {
    private ListView listView;
    private Button search;
    private EditText et;
    private SearchAdapter adapter;
    private String s;

    @Override
    protected int setLayout() {
        return R.layout.activity_search;
    }

    @Override
    protected void initView() {
        listView = bindView(R.id.activity_search_fragmentll);
        search = bindView(R.id.activity_search_btn);
        et = bindView(R.id.activity_search_et);
        search.setOnClickListener(this);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

//                List<MusicBean> musicList = getMusicBeanFromArray();
                EventBus.getDefault().post(position);
            }
        });
    }

    @Override
    protected void initData() {
        adapter = new SearchAdapter(this);


    }


    @Override
    public void onClick(View v) {
        Toast.makeText(this, "正在努力加载中,请确定期间手机联网状态", Toast.LENGTH_SHORT).show();
        s = URLValuas.SEARCH_FRONT + FormatCodeUtil.codingFormat(et.getText().toString()) + URLValuas.SEARCH_BEHIND;
        netTool.getNetData(s, SearchBean.class, new NetTool.NetListener<SearchBean>() {
            @Override
            public void onSuccess(SearchBean searchBean) {
                List<SearchBean.ResultBean.SongInfoBean.SongListBean> songListBeen = searchBean.getResult().getSong_info().getSong_list();
                listView.setAdapter(adapter);
                adapter.setSongListBeen(songListBeen);

            }

            @Override
            public void onError(String errorMsg) {

            }
        });

    }

//    private void  getMusicInfo(final int pos, final String url){
//        netTool.getNetData(s, SearchBean.class, new NetTool.NetListener<SearchBean>() {
//            @Override
//            public void onSuccess(SearchBean searchBean) {
//                MusicBean musicBean = new MusicBean();
//                musicBean.setUrl(searchBean.getResult().getSong_info().getSong_list().get(pos).getSong_id());//获取 歌曲网址
//                musicBean.setMusicName(searchBean.getSonginfo().getTitle());//歌名
//                musicBean.setSingerPic(searchBean.getSonginfo().getPic_small());//图片
//                musicBean.setSingerName(searchBean.getSonginfo().getAuthor());//歌手
//                musicBean.setBigpic(searchBean.getSonginfo().getPic_huge());//da tu pian
//                musicBean.setTitle(searchBean.getSonginfo().getAlbum_title());
//                musicBean.setLrcUrl(searchBean.getSonginfo().getLrclink());
//
//
//
//            }
//
//            @Override
//            public void onError(String errorMsg) {
//
//            }
//        });
//    }

}
